public class Text3 {
    public static void main(String[] args) {
        int[] arr = {1,2,3,4,5};
        int ret = fun(arr,5);
        System.out.println(ret);
    }
    public static int fun(int[] arr,int n){
        int front = 0;
        int rear  = arr.length-1;
        while(front <= rear){
            int mid = (rear + front)/2;//防止溢出
            if(arr[mid] == n ){
                return mid;
            }else if(arr[mid] < n){
                front= mid + 1;
            }else if(arr[mid] > n){
                rear = mid - 1;
            }
        }
        return -1;
    }
}
